<template>
  <Card title="全年设备数据分析">
    <div slot="extra">
      <timeType  @changeTimeType="changeTimeType"></timeType>
    </div>
    <chart  :data="charData"></chart>
  </Card>
</template>

<script>
import chart from "../echarts/chart";
import {deviceCountOnDateAndModel} from '@/api/realtimeData';
import base from '@/mixins/base';
import timeType from "./timeType";
export default {
  mixins:[base],
  components:{chart,timeType},
  name: "alarmEventInfo",
  data(){
    return {
      charData:[]
    }
  },
  mounted() {
    this.getData();
  },
  methods:{
    async getData(){
      let res =!this.orgIds?{}: await deviceCountOnDateAndModel({pOrgId:this.orgIds,dateType:this.dateType});
      let data=_.get(res,'data')||{}
      this.charData=[];
      if((_.get(data,'date')||[])){
        this.charData.push({
          data:this.formatData(data),
          type:'bar'
        })
      }

    },
    formatData(data){
      let _arr=[];
      if((_.get(data,'date')||[]).length&&(_.get(data,'value')||[]).length){
        _arr= (_.get(data,'value.0.data')||[]).map((item,index)=>{
          return {
            label:_.get(data,'date.'+index),
            value:item
          }
        })
      }
      return _arr;
    }
  },
}
</script>

<style scoped>

</style>
